<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>${alert}
  	<style>
  		.input-group-addon {
  			background-color: #ffffff;
  			border: 0px;
  		}
  	</style>
  	<link rel="stylesheet" type="text/css" href="assets/css/lightbox.css" />
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>브랜드 조회/수정</h2>
		</div>

		<form id="updateBrand" class="form-horizontal" role="form" method="post" action="updateBrand.do" enctype="multipart/form-data">
			<fieldset>
				
				<div class="form-group">
					<label for="isDisplay" class="col-md-2 control-label">상태</label>
					<div class="col-md-10">
						<label class="radio-inline">
							<input type="radio" name="isDisplay" value="1" <c:if test="${cmd.isDisplay == 1}">checked</c:if>> 노출
						</label>
						<label class="radio-inline">
							<input type="radio" name="isDisplay" value="0" <c:if test="${cmd.isDisplay == 0}">checked</c:if>> 미노출
						</label>
					</div>
				</div>

				<div class="form-group">
					<label for="idBrand" class="col-md-2 control-label">브랜드번호</label>
					<div class="col-md-10">
						<input type="hidden" name="idBrand" value="${cmd.idBrand}"/>
						<p class="form-control-static">${cmd.idBrand}</p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="brandTitle" class="col-md-2 control-label">브랜드명</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="brandTitle" value="${cmd.brandTitle}"/>
					</div>
				</div>

				<div class="form-group">
					<label for="created_date" class="col-md-2 control-label">등록일</label>
					<div class="col-md-10">
						<p class="form-control-static">${fn:substring(cmd.create_date, 0, 4)}-${fn:substring(cmd.create_date, 4, 6)}-${fn:substring(cmd.create_date, 6, 8)}</p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="brandImg" class="col-md-2 control-label">로고</label>
					<div class="col-md-10">
						<div class="row">
							<div class="col-md-4">
								<p class="form-control-static">
									<a href="download.jsp?${image}" data-lightbox="roadtrip" title="${cmd.brandTitle}">
										<img src="download.jsp?${image}" class="img-thumbnail img-responsive"/>
									</a>
								</p>
							</div>
							<div class="col-md-8">
								<br/>
								<ul>
									<li>항번: ${image.idAttacheFile}</li>
									<li>원본 파일 이름: ${image.fileOrgName}</li>
									<li>파일 크기: ${image.fileSize}byte</li>
									<li>업로드된 파일 이름: ${image.fileSaveName}</li>
									<li>업로드된 폴더 경로: ${image.fileDir}</li>
									<li>파일 타입: ${image.fileType}</li>
								</ul>
								&nbsp;&nbsp;&nbsp;&nbsp;
								<button type="button" class="btn btn-sm" id="imgEdit">변경</button>
								<br/><br/>
								<div id="imgDiv"><input type="file" class="form-control" name="editImg"/></div>
							</div>
						</div>
						
					</div>
				</div>

				<div class="form-group">
					<label for="homepage" class="col-md-2 control-label">홈페이지</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="homepage" value="${cmd.brandUrl}"/>
					</div>
				</div>

				<div class="form-group">
					<label for="facebook" class="col-md-2 control-label">페이스북</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="facebook" value="${cmd.brandFacebook}"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="twitter" class="col-md-2 control-label">트위터</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="twitter" value="${cmd.twitter}"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="kakaotalk" class="col-md-2 control-label">카카오톡</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="kakaotalk" value="${cmd.kakaotalk}"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="youTube" class="col-md-2 control-label">유투브</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="youTube" value="${cmd.youTube}"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="tel1" class="col-md-2 control-label">연락처</label>
					<div class="col-md-10 input-group input-group-sm">
						<input type="number" class="form-control" name="tel1" value="${tel0}">
						<span class="input-group-addon">ㅡ</span>
						<input type="number" class="form-control" name="tel2" value="${tel1}">
						<span class="input-group-addon">ㅡ</span>
						<input type="number" class="form-control" name="tel3" value="${tel2}">
					</div>
				</div>

				<div class="form-group">
					<label for="countProduct" class="col-md-2 control-label">제품수</label>
					<div class="col-md-10">
						<p class="form-control-static">
							<a href="listProduct.do?where= AND p.idBrand=${cmd.idBrand}"
								target="_blank">${cmd.productCount}</a>
						</p>
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" id="updateConfirm" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>
					</div>
				</div>

			</fieldset>
		</form>
	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="assets/js/string.js"></script>
	<script src="assets/js/lightbox-2.6.min.js"></script>
	<script type="text/javascript">
		// jquery main()
		$(function() {
			$("#updateBrand").submit(function() {
				
				if (!$("input[name='isDisplay']").is(":checked")) {
					alert("노출상태를 선택해 주세요");
					$("input[name='isDisplay']").focus();
					return false;
				}
				
				if (!$("input[name='brandTitle']").val().isValue()) {
					alert("브랜드명을 입력하세요.");
					$("input[name='brandTitle']").focus();
					return false;
				}
				
				if ($("input[name='homepage']").val().isValue()) {
					if (!$("input[name='homepage']").val().isUrl()) {
						alert("홈페이지의 형식에 맞지 않습니다.");
						$("input[name='homepage']").focus();
						return false;
					}
				}
				
				if ($("input[name='facebook']").val().isValue()) {
					if (!$("input[name='facebook']").val().isUrl()) {
						alert("페이스북 주소 형식에 맞지 않습니다.");
						$("input[name='facebook']").focus();
						return false;
					}
				}
				
				if ($("input[name='twitter']").val().isValue()) {
					if (!$("input[name='twitter']").val().isUrl()) {
						alert("트위터 주소 형식에 맞지 않습니다.");
						$("input[name='twitter']").focus();
						return false;
					}
				}
				
				if ($("input[name='youTube']").val().isValue()) {
					if (!$("input[name='youTube']").val().isUrl()) {
						alert("유투브 주소 형식에 맞지 않습니다.");
						$("input[name='youTube']").focus();
						return false;
					}
				}
				
				/* if (!$("input[name='tel1']").val().isValue()) {
					alert("연락처 앞번호를 입력하세요.");
					$("input[name='tel1']").focus();
					return false;
				}
				
				if (!$("input[name='tel1']").val().isNumber()) {
					alert("연락처 앞번호는 숫자로만 입력이 가능합니다.");
					$("input[name='tel1']").focus();
					return false;
				}
				
				if (!$("input[name='tel2']").val().isValue()) {
					alert("연락처 중간번호를 입력하세요.");
					$("input[name='tel2']").focus();
					return false;
				}
				
				if (!$("input[name='tel2']").val().isNumber()) {
					alert("연락처 중간번호는 숫자로만 입력이 가능합니다.");
					$("input[name='tel2']").focus();
					return false;
				}
				
				if (!$("input[name='tel3']").val().isValue()) {
					alert("연락처 뒷번호를 입력하세요.");
					$("input[name='tel3']").focus();
					return false;
				}
				
				if (!$("input[name='tel3']").val().isNumber()) {
					alert("연락처 뒷번호는 숫자로만 입력이 가능합니다.");
					$("input[name='tel3']").focus();
					return false;
				} */
				
				if (!confirm("정말 수정하시겠습니까?")) {
					return false;
				}
			});
		});
	</script>
	<script>
		$(function() {
			$("#imgDiv").hide();
			
			$("#imgEdit").click(function() {
				$("input[name='editImg']").replaceWith($("input[name='editImg']").clone(true));
				$("#imgDiv").toggle();
			});
		});
	</script>
  </body>
</html>